# mtp_phone_connect
# Builds from https://github.com/puppylinux-woof-CE/petbuilds

#URL= the shell source is included in templeate
PKG=mtp_phone_connect
TODAY=`date +%y%m%d`
VER=$TODAY
STATUS_URL=http://distro.ibiblio.org/puppylinux/sources/m/
STATUS_PKG=mtpstatus
STATUS_VER=0.5
STATUS_COMP=tar.gz
GO_URL=http://hanwen.home.xs4all.nl/public/software/go-mtpfs/
GO_PKG=
DESC="Connect Android phones and tablets over usb"
DEPS=+gtk+2,+fuse
CAT=Filesystem
CWD=`pwd`

ARCH=`uname -m`
case $ARCH in
 *64) LIBDIR=lib64 
	GO_PKG=go-mtpfs.x86_64;;
 *) LIBDIR=lib 
	GO_PKG=go-mtpfs.x86;;
esac

retrieve() {
	[ -f "${STATUS_PKG}-${STATUS_VER}.${STATUS_COMP}" ] ||\
	 wget -t0 -c ${STATUS_URL}/${STATUS_PKG}-${STATUS_VER}.${STATUS_COMP}
	[ -f "${GO_PKG}" ] ||\
	 wget -t0 -c ${GO_URL}/${GO_PKG}
}

extract() {
	tar -xvf ${STATUS_PKG}-${STATUS_VER}.${STATUS_COMP}
	[ "$?" -eq 0 ] || exit
}

build() {
	mv $PKG-template  $PKG-$VER-${ARCH}
	# since not X compiling forget build triplet
	cd ${STATUS_PKG}-${STATUS_VER}
	make
	[ "$?" -eq 0 ] || exit
	strip --strip-unneeded ${STATUS_PKG} 
	install -m 0755 ${STATUS_PKG} $CWD/${PKG}-${VER}-${ARCH}/usr/bin
	make clean
	cd -
	install -m 0755 ${GO_PKG} $CWD/${PKG}-${VER}-${ARCH}/usr/bin #can't strip!
}
	
package() {
	# add this recipe
	install -d -m 0755 ./$PKG-$VER-$ARCH/usr/share/doc
	cat ${PKG}.petbuild > ./$PKG-$VER-$ARCH/usr/share/doc/$PKG-build-recipe
	if [ "$DESKTOP" ];then
		install -d -m 0755 ./$PKG-$VER-$ARCH/usr/share/applications
		cat $DESKTOP > ./$PKG-$VER-$ARCH/usr/share/applications/$DESKTOP
	fi
	# delete any icon cache or library cache
	find ./$PKG-$VER-$ARCH -type f -name '*cache' -delete
	[ -f ./pinstall.sh ] && install -m 0755 pinstall.sh ./$PKG-$VER-$ARCH/
	[ -f ./puninstall.sh ] && install -m 0755 puninstall.sh ./$PKG-$VER-$ARCH/
	for p in `ls|grep "\-${ARCH}"|grep -v "files$"` ; do
		case $p in
			*_DEV*) DESC="$PKG development"; DEPS=+${PKG} ;;
			*_DOC*) DESC="$PKG documentation"; DEPS=+${PKG} ;;
			*_NLS*) DESC="$PKG locales"; DEPS=+${PKG} ;;
		esac	
		dir2pet -x -s -w="$DESC" -d="$DEPS" -c=$CAT -p=${p} 2>&1 >/dev/null
	done
	echo "done!"
}

# main
retrieve
extract
build
package	
